import { fromJS } from 'immutable'; // 引入immutable.js库，防止state对象被错误赋值

// immutable对象
const defaultState = fromJS({
    topicList: [],
    list: [],
    writerList: [],
    page: 1,
    showScroll: false,
});

const reducer = (state = defaultState, action) => {
    switch (action.type) {
        case 'HOME_INFO':
            let { topicList, list, writerList } = action.data;
            return state.merge({
                topicList,
                list,
                writerList,
            });
        case 'HOME_LIST':
            return state.merge({
                list: state.get('list').concat(action.list),
                page: action.page,
            });
        case 'CHANGE_SCROLL':
            return state.set('showScroll', action.showScroll);
        default:
            return state;
    }
};

export default reducer;
